#!/bin/sh
###############################################################################
# This tool provides an interactive interface to a number of scripts that can 
# be used to automatically update and tweak your ASUS EeePC mini-laptop.   It 
# will try to ensure that the environment is stable and all pre-requisites are 
# met before attempting any operation that modifies the system.
###############################################################################

# (c) copyright Clinton Webb, 2008
# Licensed under GPL.

# Check and install repositories (as needed).
# Add applications to the Easy menu.
#  - konsole
#  - kate
#  - krdc - remote desktop
#  - kolourpaint
#
# Peripherals.
#	Logitech vt320
#	Logitech vx nano
# Thermal sensing
# Over-clocking
# Battery performance enhancements.


# Add any additional things from the eeeuser wiki.


applications() {
  kdialog --msgbox "This option would generally allow you to add extra applications to your Easy Launcher"
}

go_eeeuser() {
/usr/bin/firefox http://www.eeeuser.com/ &
}


change_hostname() {
  if [ -x scripts/change-hostname ]; then
    scripts/change-hostname
  else
    kdialog --title "EeePC Config" --sorry "The scripts/change-hostname script is either not there, or is not executable.  Something is not configured right."
  fi
}

# This option replaces the /sbin/probedevices script so that it removes the sync option 
# and replaces it with the noatime option that will improve write performance on sd 
# cards and usb devices.
change_probe() {
  # get an md5sum of the device.
  SUM=`md5sum /sbin/probedevice | awk '{print($1)}'`
  # compare it with our known md5sum
  if [ "$SUM" = "eb442363a0c03a0964abba2971b730fb" ]; then
    # if md5 is ok, then we will make the change.
    sudo cp files/probedevice /sbin/
    kdialog --msgbox "The /sbin/probedevice script has been modified.  To enable the changes you will need to eject your sd and flash drive and re-insert them"
  else 
    # if md5 is not ok, then tell the user that the script has already been changed.
    kdialog --sorry "The /sbin/probedevice file was already modified.  No additional changes have been made.  You will need to examine the file manually."
  fi
}


config() {
  local TASK=unknown
  local EXIT=0
  while [ $EXIT -eq 0 ]; do
    TASK=$(kdialog --title "Configuration" \
      --menu "Configuration" \
        HOSTNAME "Change Hostname" )

    test $? -ne "0" && EXIT=1

    case "$TASK" in
      HOSTNAME)  change_hostname    ;;
    esac
  done
}

all_tweaks() {
  change_probe
}

tweaks() {
  local TASK=unknown
  local EXIT=0
  while [ $EXIT -eq 0 ]; do
    TASK=$(kdialog --title "Tweaks" \
      --menu "Tweaks" \
        PROBE "Improve performance for ext2/ext3 on sd and flash" \
	ALL   "All Tweaks" )

    test $? -ne "0" && EXIT=1

    case "$TASK" in
      PROBE)  change_probe    ;;
      ALL)    all_tweaks      ;;
    esac
  done
}

more_info() {
  local TASK=unknown
  local EXIT=0
  while [ $EXIT -eq 0 ]; do
    TASK=$(kdialog --title "More information sources" \
      --menu "More information sources" \
        EEEUSER "eeeuser.com" )

    test $? -ne "0" && EXIT=1

    case "$TASK" in
      EEEUSER)  go_eeeuser    ;;
    esac
  done
}


main() {
  TASK=unknown
  while [ 1 ] ; do

    TASK=$(kdialog --title "EeePC Config" \
      --menu "What do you want to do?" \
        APPS "Applications" \
        CONFIG "Configuration" \
        TWEAKS "Tweaks" \
        MORE "More Information" )

    test $? -ne "0" && exit

    case "$TASK" in
      APPS)     applications    ;;
      CONFIG)   config          ;;
      TWEAKS)   tweaks          ;;
      MORE)     more_info       ;;
    esac
  done
}

system_check() {
  # check the hardware, make sure it conforms
  # check the bios, warn if it is lower.  Fail if it is higher.
  # check available storage space
  sleep 1
  #  kdialog --msgbox "..."
}


system_check
main

